package file;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;

import kr.db.MySql;

public class fileDTO {
	
	Connection conn;
	
	public fileDTO() {
		
		conn = new MySql().getConn();
		System.out.println();
	}
	
	public boolean fileInfoInsert(Vector<FileInfoVO> vector_fileInfo, String sendUser, Vector<String> v_filer){
		
		System.out.println("v_filer사이즈: "+v_filer.size());
		
		for(int j=0; j<vector_fileInfo.size(); j++){
			System.out.println("[업로드]보내는 사람: "+sendUser);
			System.out.println("[업로드]파일 명: "+vector_fileInfo.get(j).getFileName());
			System.out.println("[업로드]파일 경로 :"+vector_fileInfo.get(j).getFilePath());
			System.out.println("[업로드]파일 사이즈 :"+vector_fileInfo.get(j).getFileSize());
			for(int k=0; k<v_filer.size(); k++){
				System.out.println("[업로드]받는 사람: "+v_filer.get(k));
			}
		}
		
		boolean flag = false;
		
		//download
		String sql = " insert into file (file_upload_employee_id, file_download_employee_id, file_download_filename, file_download_date, file_division) values (?, ?, ?, now(), 'download') ";
		
		try {
		PreparedStatement psmt = conn.prepareStatement(sql);
		
		for(int i=0; i<v_filer.size(); i++){
			psmt.setString(1, sendUser);
			psmt.setString(2, String.valueOf(vector_fileInfo.get(i)));
			psmt.setString(3, "C:/upload"+vector_fileInfo.get(i).getFileName());
		}
		
		int affectedRow = psmt.executeUpdate();
		
		if(affectedRow > 0) flag = true;
		else flag = false;
		
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return flag;
	}
}
